package com.aiml;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Scanner;

import com.topwalk.FileUtil;
import com.topwalk.PropertiesObject;
import com.topwalk.ReadProperties;
import com.topwalk.UnZip;

/**
 * 测试压缩包解压以及文件移动位置。
 * <p>
 * -----------------------------------------------------------------------------
 * <p>
 * 工程名 ： IWP
 * <p>
 * 授权 : (C) Copyright TopWalk Corporation 2011
 * <p>
 * 公司 : 北京天行网安信息技术有限责任公司
 * <p>
 * -----------------------------------------------------------------------------
 * <p>
 * <font color="#FF0000">注意: 本内容仅限于北京天行网安公司内部使用，禁止转发</font>
 * <p>
 * @version 1.0
 * @author 张华永
 * @lastModify 2011-11-11
 * @since JDK1.6
 */
public class Test {
	
	private static String app_filename;
	private static String app_web_inf;
	private static String app_page;
	
	public static void main(String[] args) {

		ReadProperties rp = new ReadProperties();
		/**
		 * 获取解压文件存放目录
		 */
		String src_dir = rp.getUnZipFileDir();
		
		String outputDirectory = src_dir;
		
		Scanner scanner = new Scanner(System.in);		
		System.out.print("请输入源文件路径：");	//eg:D:/IWP.zip
		String src_zip = scanner.next();
		
		/**
		 * 将压缩包文件解压到指定的目录
		 */
		UnZip.unZipMain(outputDirectory, src_zip);		
		
		List<PropertiesObject> list = rp.readProperties("install.properties");
		for(PropertiesObject po : list){
			if("app_filename".equalsIgnoreCase(po.getKey())){				
				app_filename = po.getValue();				
			}else if("app_web_inf".equalsIgnoreCase(po.getKey())){
				app_web_inf = po.getValue();
			}else if("app_page".equalsIgnoreCase(po.getKey())){
				app_page = po.getValue();
			}
		}
		System.out.println("app_filename:"+app_filename);
		System.out.println("app_web_inf:"+app_web_inf);
		System.out.println("app_page:"+app_page);		
		
		System.out.print("请输入WEB-INF目的路径："); //eg:D:/TMP/IWP/
		String toDir = scanner.next();
		
		try {
			FileUtil.FileUtilMain(src_dir+app_filename+"/"+app_web_inf, toDir);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		System.out.print("请输入page目的路径："); //eg:D:/TMP/IWP/
		String toDir2 = scanner.next();
		
		/*try {
			FileUtil.FileUtilMain(src_dir+app_filename+"/"+app_page, toDir2);
		} catch (IOException e) {
			e.printStackTrace();
		}*/
		
		System.out.println("将文件夹名称改为：");
		String newName = scanner.next();
		
		
		String[] new_name = newName.split("/");
		String tmp_name = "";
		for(int i=0;i<new_name.length-1;i++){
			tmp_name += new_name[i] + "/";
		}
		System.out.println(tmp_name);
		try {
			FileUtil.FileUtilMain(src_dir+app_filename+"/"+app_page, toDir2+tmp_name);
		} catch (IOException e) {
			e.printStackTrace();
		}
		String str1 = toDir2+tmp_name+app_page;
		String str2 = toDir2+tmp_name+new_name[new_name.length-1];
		System.out.println(str1+"\n"+str2);
		File oldFile = new File(str1);
		oldFile.renameTo(new File(str2));
		System.out.println("文件夹改名成功。");
	}

}
